﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using DapperExtensions;

namespace Dapper.Core.Data
{
    //https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates
    public abstract class Repository<TEntity, TKey> where TEntity : EntityBase<TKey>
    {
        public IDbConnection _db = ConnectionProvider._dbConnection;


        public TEntity GetById(TKey key)
        {

            return _db.Get<TEntity>(key);
        }

        public int Insert(TEntity entity)
        {
            return _db.Insert(entity);
        }

        public void Insert(IEnumerable<TEntity> entities)
        {
            _db.Insert(entities);
        }

        public void Delete(TEntity entity)
        {
            _db.Delete(entity);
        } 

        public bool Update(TEntity entity)
        {
            return _db.Update(entity);
        }
    }
}
